var util = require('../../utils/utils.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    expressIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      opasId: options.opasId
    })
 },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + 'getAllExpressCompany',
      method: "get",
      success: function (res) {
        that.setData({
          express: res.data.data,
        })
        for (var i = 0; i < res.data.data.length; i++) {
          var code = res.data.data[0].code;
          var company = res.data.data[0].company;
        }
        that.setData({
          code: code,
          company: company
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
  navBack: function () {
    wx.navigateBack({

    })
  },
  bindCountryChange(e) {
    var that = this;
    var val = e.detail.value;
    var express = that.data.express;
    for (var i = 0; i < express.length;i++){
      var code = express[val].code;
      var company = express[val].company;
    }
    this.setData({
      multiIndex: that.data.multiIndex,
      code: code,
      company: company
    })
    this.setData({
      expressIndex: e.detail.value
    })
    
  },
  num:function(e){
    var that = this;
    that.setData({
      num: e.detail.value
    })
  },
  phone: function (e) {
    var that = this;
    that.setData({
      phone: e.detail.value
    })
  },
  bindSubmitOrder:function(){
    var that = this;
    wx.request({
      url: app.globalData.url + 'userFillInExpressNumberForReturns',
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        opasId: that.data.opasId,
        expressNum: that.data.num,
        expressCompany: that.data.company,
        expressCompanyCode:that.data.code,
        telephone: that.data.phone,
      },
      success: function (res) {
        if (res.data.result==1) {
          wx.showToast({
            title: '提交成功！',
            type: "success",
          });
          wx.navigateBack({
            
          })
        }
      }
    })
  },
})